package com;


import javax.jws.soap.SOAPBinding;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

interface Converter<Source,Target>{}
abstract class OneWayConverter<Source,Target> implements Converter{
    Function<Source,Target> function;

    public OneWayConverter(Function<Source, Target> function) {
        this.function = function;
    }
    public Target convertTo(Source source){
        return function.apply(source);
    }
    public List<Target> converTo(List<Source> sources){
        return sources.stream().map(this::convertTo).collect(Collectors.toList());
    }

}
class Boy{
     String sex;
     String name;

    @Override
    public String toString() {
        return "Boy{" +
                "sex='" + sex + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
class ChangeBoy{
    String sex;
    String name;

    @Override
    public String toString() {
        return "ChangeBoy{" +
                "sex='" + sex + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
class ChangeGirl extends  OneWayConverter<Boy,ChangeBoy>{
    public ChangeGirl() {
        super(ChangeGirl::change);
    }

    private static ChangeBoy change(Boy boy) {
        ChangeBoy changeBoy = new ChangeBoy();
        changeBoy.sex ="女性";
        changeBoy.name="飞姐";
        return changeBoy;
    }
}

/**
 * 类型转换接口实例
 */
public class FunctionConverter {
    public static ChangeBoy feige(Boy boy){
        System.out.println(boy.toString());
        ChangeGirl changeGirl = new ChangeGirl();
        ChangeBoy changeBoy =  changeGirl.convertTo(boy);
        System.out.println(changeBoy.toString());
        return changeBoy;
    }
    public static void main(String[] args) {
        Boy boy = new Boy();
        boy.name = "飞哥";
        boy.sex ="男性";
        feige(boy);


    }
}
